package com.coldchain.cys.api;

import com.coldchain.authclient.annotation.CheckClientToken;
import com.coldchain.authclient.annotation.CheckUserToken;
import com.coldchain.common.msg.BaseResponse;
import com.coldchain.common.msg.ObjectRestResponse;
import com.coldchain.cys.entity.Cys;
import com.coldchain.cys.mapping.ApiUtils;
import com.coldchain.cys.page.CysQueryVo;
import com.coldchain.cys.service.ICysService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tianpeng
 * @since 2018-08-28
 */
@RestController
@Api(description="承运商系统主模块")
public class CysController {
	
	@Autowired
	private ICysService cysService ;
	
	
	@ApiOperation(value="查询承运商列表")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="current",value="页码",dataType="Integer",paramType="query"),
	})
	@RequestMapping(value=ApiUtils.SHOW_CYS_LIST,method={RequestMethod.GET})
	@CheckUserToken
	public ObjectRestResponse<CysQueryVo> showCysList(@ApiIgnore CysQueryVo vo){
		cysService.getList(vo) ;
		return new ObjectRestResponse<CysQueryVo>(vo); 
	}
	
	@ApiOperation(value="查询承运商详情")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="id",value="承运商id",dataType="Long",paramType="path"),
	})
	@RequestMapping(value=ApiUtils.SHOW_CYS_DETAIL + "/{id}",method={RequestMethod.GET})
	@CheckUserToken
	public ObjectRestResponse<Object> showCysDetail(@ApiIgnore @PathVariable Long id){
		Cys cys = cysService.getCysDetail(id) ;
		if(cys == null){
			return new ObjectRestResponse<Object>("无权访问") ;
		}
		return new ObjectRestResponse<Object>(cys) ; 
	}

	@ApiOperation(value="验证承运商登录")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="username",value="承运商用户名",dataType="String",paramType="query"),
		@ApiImplicitParam(name="password",value="承运商密码",dataType="String",paramType="query")
	})
	@RequestMapping(value=ApiUtils.VALIDATE_CYS_LOGIN,method={RequestMethod.POST})
	public BaseResponse validateCysLogin(@RequestParam("username") @ApiIgnore String username
			, @RequestParam("password") @ApiIgnore String password){
		return cysService.validateCysLogin(username,password) ;
	}
	
	@ApiOperation(value="删除承运商")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="cysId",value="承运商id",dataType="Long",paramType="query"),
	})
	@CheckUserToken
	@CheckClientToken
	@RequestMapping(value=ApiUtils.DO_DELETE_CYS,method= {RequestMethod.POST})
	public BaseResponse doDeleteCys(@ApiIgnore Long cysId) {
		return cysService.doDeleteCys(cysId) ;
	}
	
	@ApiOperation(value="承运商启用禁用开关")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="cysId",value="承运商id",dataType="Long",paramType="query"),
	})
	@CheckUserToken
	@CheckClientToken
	@RequestMapping(value=ApiUtils.DO_SWITCH_CYS_USE,method= {RequestMethod.POST})
	public BaseResponse doSwitchCysUse(@ApiIgnore Long cysId) {
		return cysService.doSwitchCysUse(cysId) ;
	}
	
	@ApiOperation(value="添加承运商")
	@ApiImplicitParams(value={
		@ApiImplicitParam(name="name",value="承运商名称",dataType="String",paramType="query"),
		@ApiImplicitParam(name="enterpriseName",value="企业名称",dataType="String",paramType="query"),
		@ApiImplicitParam(name="area",value="地区",dataType="String",paramType="query"),
		@ApiImplicitParam(name="phone",value="手机号码",dataType="String",paramType="query"),
		@ApiImplicitParam(name="scale",value="拔出佣金比例",dataType="Decimal",paramType="query"),
	})
	@CheckUserToken
	@CheckClientToken
	@RequestMapping(value=ApiUtils.DO_ADD_CYS,method= {RequestMethod.POST})
	public BaseResponse doAddCys(@ApiIgnore Cys cys) {
		return cysService.doAddCys(cys) ;
	}
}
